

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:fluttertoast/fluttertoast.dart';

import '../../home/widget/base/LoadStateLayout.dart';

class ChangeLoadStateLayout extends StatefulWidget{

  @override
  State<StatefulWidget> createState() => _ChangeLoadStateLayoutState();

}
class _ChangeLoadStateLayoutState extends State<ChangeLoadStateLayout>{
  LoadState loadState = LoadState.State_Loading;
  String text = '111';

  void update(LoadState state){
    setState(() {
      loadState = state;
      text = state.name;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(onPressed: () {
          update(LoadState.State_Error);
          Fluttertoast.showToast(msg: 'change2Error');
        }, child:  Text('chang2Error${text}')),
        ElevatedButton(onPressed: ()=> update(LoadState.State_Empty), child:  Text('chang2Empty${text}')),
        ElevatedButton(onPressed: ()=> update(LoadState.State_Success), child:  Text('chang2Success${text}')),
        ElevatedButton(onPressed: ()=> update(LoadState.State_Loading), child:  Text('chang2Loading${text}')),
        Container(
          width: double.maxFinite,
          height: 200,
          child:  LoadStateLayout(
            successWidget: Container(
              color: Colors.blue,
              child: Text('hahshadhahksdhjlajflasjf;ljaljfl;kasjl;djakljf'),
            ),
            state: loadState,
            errorRetry: () {
              loadState = LoadState.State_Loading;
              Future.delayed(Duration(seconds: 2),() {
                loadState = LoadState.State_Success;
              },);
            },
          ),
        )
      ],
    );
  }

}